{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['../data/POS_CASH_balance',\n",
       " '../data/bureau',\n",
       " '../data/bureau_balance',\n",
       " '../data/credit_card_balance',\n",
       " '../data/installments_payments',\n",
       " '../data/label',\n",
       " '../data/previous_application',\n",
       " '../data/sub.p',\n",
       " '../data/test',\n",
       " '../data/train']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from glob import glob\n",
    "import numpy as np\n",
    "import utils\n",
    "sorted(glob('../data/*'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def sample(n=10):\n",
    "    df = utils.load_train()\n",
    "    ids = np.random.choice(df.SK_ID_CURR.unique(), size=n, replace=False)\n",
    "    df[df.SK_ID_CURR.isin(ids)].sort_values('SK_ID_CURR').to_csv('../sample/sample_tr.csv', index=False)\n",
    "    \n",
    "    df = utils.read_pickles('../data/POS_CASH_balance')\n",
    "    df = df[df.SK_ID_CURR.isin(ids)]\n",
    "    df.sort_values(['SK_ID_CURR', 'MONTHS_BALANCE'], ascending=[True, False]).to_csv('../sample/sample_POS.csv', index=False)\n",
    "    \n",
    "    df = utils.read_pickles('../data/bureau')\n",
    "    df = df[df.SK_ID_CURR.isin(ids)]\n",
    "    df.sort_values(['SK_ID_CURR', 'DAYS_CREDIT'], ascending=[True, False]).to_csv('../sample/sample_bure.csv', index=False)\n",
    "    \n",
    "    df = utils.read_pickles('../data/credit_card_balance')\n",
    "    df = df[df.SK_ID_CURR.isin(ids)]\n",
    "    df.sort_values(['SK_ID_CURR', 'MONTHS_BALANCE'], ascending=[True, False]).to_csv('../sample/sample_cre.csv', index=False)\n",
    "    \n",
    "    df = utils.read_pickles('../data/installments_payments')\n",
    "    df = df[df.SK_ID_CURR.isin(ids)]\n",
    "    df.sort_values(['SK_ID_CURR', 'DAYS_INSTALMENT'], ascending=[True, False]).to_csv('../sample/sample_ins.csv', index=False)\n",
    "    \n",
    "    df = utils.read_pickles('../data/previous_application')\n",
    "    df = df[df.SK_ID_CURR.isin(ids)]\n",
    "    df.sort_values(['SK_ID_CURR', 'DAYS_DECISION'], ascending=[True, False]).to_csv('../sample/sample_prev.csv', index=False)\n",
    "    \n",
    "    return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 20/20 [00:03<00:00,  5.33it/s]\n",
      "100%|██████████| 20/20 [00:05<00:00,  3.64it/s]\n",
      "100%|██████████| 20/20 [00:04<00:00,  4.54it/s]\n",
      "100%|██████████| 20/20 [00:07<00:00,  2.86it/s]\n",
      "100%|██████████| 20/20 [00:13<00:00,  1.53it/s]\n",
      "100%|██████████| 20/20 [00:07<00:00,  2.50it/s]\n"
     ]
    }
   ],
   "source": [
    "sample(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
